#include<stdio.h>
#include<stdlib.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<string.h>
#include<unistd.h>



int read_Line(int fd,void *buffer,size_t buff_len)
{
    int r_c;
    int i = 0;
    memset(buffer,0,buff_len);
    char *buff=(char *)buffer;
    char temp;
    while ( (r_c = read(fd,&temp,1)) >= 0)
    {
        if(i>=buff_len)
        {
            return buff_len;
        }
        if(r_c = 0)
        {
            return 0;
        }
        else if(temp == '\n')
        {
            buff[i]='\0';
            return i;
        }
        else{
            buff[i]=temp;
        }
        i++;
        
    }
    return -1;
}
int write_len(int fd,void *buffer,size_t buff_len)
{
    write(fd,buffer,buff_len);
    write(fd,"\n",1);
}
int main(int argc,char**argv)
{
    if(argc != 2)
    {
        printf("please input filename\n");
        exit(1);
    }
    int fdin,fdout;
    char buffer[1024]={0};
    if((fdin = open(argv[1],O_RDONLY)) < 0)
    {
        perror("open file failed\n");
        exit(1);
    }
   
    read_Line(fdin,buffer,sizeof(buffer)-1);
    printf("%s",buffer);
    return 0;
}